package com.leyou.item.controller;

import com.leyou.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    //展示分类列表
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<CategoryDTO>> findCategorysByPid(Long pid){
        List<CategoryDTO> list = categoryService.findCategorysByPid(pid);
        //return ResponseEntity.status(HttpStatus.OK).body(list);
       return  ResponseEntity.ok(list);
    }
    //数据回显
    @GetMapping("/category/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryByBrandId(@RequestParam(value = "id")Long id){
        return ResponseEntity.ok(categoryService.queryByBrandId(id));
    }

    @GetMapping("/category/list")
    public ResponseEntity<List<CategoryDTO>> findByCategorysByIds(@RequestParam(value = "ids")List<Long> ids){
       List<CategoryDTO> list = categoryService.findByCategorysByIds(ids);
        return ResponseEntity.ok(list);
    }



}
